package com.zmn.oms.services.impl.conf.replay;

import com.zmn.common.dto.StatusDTO;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.oms.model.entity.conf.reply.ReplyCategory;
import com.zmn.oms.model.entity.conf.reply.ReplyCategoryQuery;
import com.zmn.oms.persistence.interfaces.conf.reply.ReplyCategoryDao;
import com.zmn.oms.services.interfaces.conf.reply.ReplyCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 回访内容分类基础接口实现类
 *
 * @author tanghongjun
 * @since 2020-04-14 11:27:25
 **/
@Slf4j
@Service
public class ReplyCategoryServiceImpl implements ReplyCategoryService {

    private static final String TAG = "回访内容分类基础服务接口";

    @Resource
    private ReplyCategoryDao replyCategoryDao;

    /**
     * 描述: 根据id查询数据
     *
     * @param categId
     *            id
     * @author tanghongjun
     * @since 2020-04-14 11:27:25
     **/
    @Override
    public ReplyCategory findById(Integer categId) {

        if (Objects.isNull(categId)) {
            log.error("[{}],根据id查询数据categId为null", TAG);
            return null;
        }
        return replyCategoryDao.findById(categId);
    }

    /**
     * 描述: 按条件查询数据 支持分页
     *
     * @param query
     *            查询对象
     * @author tanghongjun
     * @since 2020-04-14 11:27:25
     **/
    @Override
    public List<ReplyCategory> listPageByQuery(ReplyCategoryQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        int count = replyCategoryDao.countByQuery(query);
        query.setTotalCount(count);
        return replyCategoryDao.listPageByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query
     *            查询对象
     * @author tanghongjun
     * @since 2020-04-14 11:27:25
     **/
    @Override
    public List<ReplyCategory> listByQuery(ReplyCategoryQuery query) {
        return replyCategoryDao.listByQuery(query);
    }

    /**
     * 描述: 根据id修改数据 id为必传
     *
     * @param replyCategory
     *            待修改数据
     * @return java.lang.Integer
     * @author tanghongjun
     * @since 2019/11/12
     **/
    @Override
    public Integer updateReplyCategoryByKey(ReplyCategory replyCategory) {

        if (Objects.isNull(replyCategory.getCategId())) {
            log.error("[{}],根据id修改数据,replyCategoryByKey为null", TAG);
            return null;
        }
        return replyCategoryDao.updateCategoryByKey(replyCategory);
    }

    /**
     * 描述: 新增数据
     *
     * @param replyCategory
     *            待新增数据
     * @return java.lang.Integer 主键key
     * @author tanghongjun
     * @since 2019/11/12
     **/
    @Override
    public Integer insert(ReplyCategory replyCategory) {
        return replyCategoryDao.insert(replyCategory);
    }

    @Override
    public Integer findMaxSort() {
        return replyCategoryDao.findMaxSort();
    }

    @Override
    public int updateStatusBatch(List<Integer> arrayIds, int status, String updater) {
        StatusDTO dto = new StatusDTO();
        dto.setIds(arrayIds);
        dto.setStatus(status);
        dto.setUpdater(updater);
        dto.setUpdateTime(DateUtil.getNow());
        return replyCategoryDao.updateStatusBatch(dto);
    }

    @Override
    public Integer updateSortKey(int id, int sort, String updater) {
        ReplyCategory replyCategory = new ReplyCategory();
        replyCategory.setCategId(id);
        replyCategory.setSort(sort);
        replyCategory.setUpdater(updater);
        replyCategory.setUpdateTime(DateUtil.getNow());
        return replyCategoryDao.updateSortKey(replyCategory);
    }

    @Override
    public Integer updateFirstLetterByKey(int id, String firstLetter, String updater) {
        ReplyCategory replyCategory = new ReplyCategory();
        replyCategory.setCategId(id);
        replyCategory.setFirstLetter(firstLetter);
        replyCategory.setUpdater(updater);
        replyCategory.setUpdateTime(DateUtil.getNow());
        return replyCategoryDao.updateFirstLetterByKey(replyCategory);
    }

}